package com.itheima.service;

import com.itheima.dao.UserMapper;
import com.itheima.domain.User;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * @author ZhangyiA
 * @describe:
 * @date 2021/06/29
 */

public class ServiceDemo {

    public static void main(String[] args) throws IOException {
        //获得核心配置文件
        InputStream resourceAsStream = Resources.getResourceAsStream("sqlMapConfig.xml");
        //获得session工厂对象
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        //获得session回话对象
        SqlSession sqlSession = sqlSessionFactory.openSession();
        // 获得 UserMapper 的动态代理对象
        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);

/*        List<User> userList = userMapper.findAll();
        for(User user : userList){
            System.out.println(user.toString());
        }*/

        User user = userMapper.findById(14);
        System.out.println(user.toString());
    }

}
